package com.poitest.controller;

import com.poitest.mapper.TPoorMapper;
import com.poitest.pojo.TPoor;
import com.poitest.pojo.TTitle;
import com.poitest.service.PoorService;
import com.poitest.service.TitleService;
import com.poitest.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("title")
public class TitleController {
    @Autowired
    TitleService titleService;
    @Autowired
    PoorService poorService;
    @RequestMapping("list")
    @ResponseBody
    public List<TTitle> list(Model model){

        List<TTitle> tTitles = titleService.selectByExample(null);
        model.addAttribute("tTitles",tTitles);
        return tTitles;
    }
    @RequestMapping("save")
    @ResponseBody
    public R save(TTitle tTitle){
        int i = titleService.insert(tTitle);
        if(i>0){
            return R.ok();
        }else{
            return R.error();
        }
    }
    @RequestMapping("del")
    @ResponseBody
    public R del(int rid){
        int i = titleService.deleteByPrimaryKey(rid);
        if(i>0){
            return R.ok();
        }else{
            return R.error();
        }
    }
    @RequestMapping("update")
    public  String update(Model model,int rid){
        TTitle tTitle = titleService.selectByPrimaryKey(rid);
        model.addAttribute("title",tTitle);
        return "update";
    }
    @RequestMapping("edit")
    @ResponseBody
    public R edit(TTitle tTitle){
        int i = titleService.updateByPrimaryKeySelective(tTitle);
        if(i>0){
            return R.ok();
        }else {
            return R.error();
        }
    }
    @RequestMapping("people")
    public String people(){
        return "people";
    }

    @RequestMapping("erweima")
    public  String erweima(Integer id,Model model){
        model.addAttribute("id",id);
        return "index-svg";
    }
    @RequestMapping("updateT")
    @ResponseBody
    public R updateT(int id){
        try {
            poorService.updateT(id);
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return  R.error();
        }
    }
}
